// 引入第三方模块来操作数据库
const mongoose = require('mongoose')

mongoose.connect('mongodb://localhost/playground', { useNewUrlParser: true })
    .then(() => console.log('数据库链接成功...'))
    .catch(err => console.log('数据库链接失败...', err))

// 创建集合规则
const courseSchema = new mongoose.Schema({
    name: String,
    author: String,
    isPublished: Boolean
})

// 使用规则创建集合
const Course = mongoose.model('Course', courseSchema)

// 创建集合实例
const course = new Course({
    name: 'node js basic',
    author: 'Mokairui',
    isPublished: true
})

course.save()
